Skip to content

Conversation

@jerome-benoit
Copy link
Contributor

@jerome-benoit jerome-benoit commented Feb 8, 2026

Follow-up to #12636.

  • Replace safeReadDir() with readdir() to propagate errors instead of returning empty arrays silently
  • Use Bun.semver.order instead of external semver import
  • Keep isDirectory() helper for cleaner checks

Related: #12632 #12603 #12602

Copilot AI review requested due to automatic review settings February 8, 2026 12:26
@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2026

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

(PR #12636 appears in the results, but that's the related "gigamonster's build fix" that this PR is explicitly a follow-up to, not a duplicate.)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the Nix Bun node_modules post-processing scripts to rely more on Bun-native APIs and (intended) stronger error propagation during canonicalization/normalization of .bun-managed modules.

Changes:

  • Replaced safeReadDir() usage with direct readdir() calls in normalize-bun-binaries.ts.
  • Switched canonicalization version ordering to Bun.semver.order and introduced an isDirectory() helper for directory checks.
  • Updated normalize script logging wording (“rewrote” → “rebuilt”).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
nix/scripts/normalize-bun-binaries.ts Removes safeReadDir() and uses direct readdir() calls when scanning .bun and package directories; adjusts log message.
nix/scripts/canonicalize-node-modules.ts Removes dynamic semver import, uses Bun.semver.order for selection sorting, and refactors directory checks via isDirectory().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 36 to 61
const semverModule = (await import(join(bunRoot, "node_modules/semver"))) as
| SemverLike
| {
default: SemverLike
}
const semver = "default" in semverModule ? semverModule.default : semverModule
const selections = new Map<string, Entry>()

for (const [slug, list] of versions) {
list.sort((a, b) => {
const left = semver.valid(a.version)
const right = semver.valid(b.version)
if (left && right) {
const delta = semver.rcompare(left, right)
if (delta !== 0) {
return delta
}
}
if (left && !right) {
return -1
}
if (!left && right) {
return 1
}
return b.version.localeCompare(a.version)
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, using the bun semver module is nice, but why remove the checks for non semver package versions? afaict, the behavior of semver.order is not specified for invalid semver strings and could lead to nondeterministic sorting: https://bun.com/docs/runtime/semver

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fec6dd2 - added isValidSemver() guard to handle invalid versions (latest, canary, git URLs) before calling Bun.semver.order.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure Bun.semver.order throws when provided invalid semver string? why not const isSemver = (s) => Bun.semver.satisfies(s, "x.x.x") which is documented to return false when s is not a semver string

Copy link
Contributor Author

@jerome-benoit jerome-benoit Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bun.semver.order throws on invalid versions (e.g. Invalid SemVer: latest), so the try/catch worked. Switched to Bun.semver.satisfies(v, "x.x.x") which is cleaner—returns false without exceptions. Fixed in bfb3a4a.

@jerome-benoit jerome-benoit force-pushed the fix/nix-missing-bun-dir-v2 branch from 3763b4f to 594fdb0 Compare February 8, 2026 22:48
@jerome-benoit jerome-benoit force-pushed the fix/nix-missing-bun-dir-v2 branch from 205fafb to 538560c Compare February 8, 2026 23:02
@rekram1-node rekram1-node merged commit 79879b4 into anomalyco:dev Feb 9, 2026
6 checks passed
fanjia1024 pushed a commit to fanjia1024/opencode that referenced this pull request Feb 10, 2026
BryceRyan pushed a commit to BryceRyan/opencode that referenced this pull request Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants